package homework.todolist.controller;

import homework.todolist.pojo.Todo;
import homework.todolist.service.TodoService;
import homework.todolist.utils.ResponseResult;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.FileNotFoundException;
import java.util.List;

@RestController
@RequestMapping("/todolist")
public class TodoController {
    @Autowired
    private TodoService todoService;

    /**
     * 创建待办事项
     * @param content 待办事项内容
     * @return
     */

    @PostMapping("createTodo")
    public ResponseResult<Todo> createTodo(String content) {

        return todoService.createTodo(content);

    }

    /**
     * 修改待办事项内容
     * @param id 待办事项id
     * @param content 新待办事项内容
     * @return
     */
    @PostMapping("updateContent")
    public ResponseResult<Void> updateContent(Integer id, String content) {
        return todoService.updateContent(id,content);
    }

    /**
     * 更新状态
     * @param id 待办事项id
     * @return
     * @apiNote 0代表未完成 1代表已完成
     */
    @PostMapping("updateStatus")
    public ResponseResult<Void> updateStatus(Integer id) {
        return todoService.updateStatus(id);
    }

    /**
     * 为待办事项添加图片
     * @param id 待办事项id
     * @param picture 图片文件
     * @return 图片地址
     */
    @PostMapping("addPicture")
    public ResponseResult<String> addPicture(Integer id, MultipartFile picture) throws FileNotFoundException {
        return todoService.addPicture(id,picture);
    }

    /**
     * 获取所有的待办事项
     * @return
     */
    @GetMapping("todos")
    public ResponseResult<List<Todo>> getTodoList() {
        return todoService.getTodoList();
    }

    /**
     * 删除指定的待办事项
     * @param id 待办事项id
     * @return
     */

    @GetMapping("deleteTodo")
    public ResponseResult<Void> deleteTodo(Integer id) {
        return todoService.deleteTodo(id);
    }
}
